//
//  AY_BookVpCell.m
//  AiYue
//
//  Created by boWen on 2023/10/19.
//

#import "AY_BookCenterVpCell.h"

@interface AY_BookCenterVpCell ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UIImageView * p_byImageView;
@property (nonatomic, strong) UILabel * p_kaitongLabel;
@property (nonatomic, strong) UILabel * p_timeLabel;
@property (nonatomic, strong) UILabel * p_chakanLabel;
@end

@implementation AY_BookCenterVpCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}

- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(8) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.p_byImageView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_common.png") andBg:[UIColor whiteColor] andRadius:0.0 andAddSubView:self.bg_View];
    self.p_byImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.p_byImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.bg_View);
    }];
    
    self.p_kaitongLabel = [AYTool createLabelWithFrame:CGRectZero andText:[NSString stringWithFormat:@"已%@",[AYMMKV getStringForKey:KT]] andTextColor:COLOR(@"#C26600") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.p_byImageView];
    [self.p_kaitongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.p_byImageView).offset(YNUM(2));
        make.right.equalTo(self.p_byImageView.mas_right).offset(YNUM(-8));
        make.height.mas_equalTo(YNUM(16));
    }];
    
    self.p_timeLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#9C5839") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(14)] andLines:1 andRadius:0 andAddSubView:self.p_byImageView];
    [self.p_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.p_byImageView).offset(YNUM(-4));
        make.left.equalTo(self.p_byImageView).offset(YNUM(16));
        make.height.mas_equalTo(YNUM(20));
    }];
    
    self.p_chakanLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"查看会员权益" andTextColor:COLOR(@"#9C5839") andBgColor:nil andFont:[UIFont systemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.p_byImageView];
    [self.p_chakanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.p_byImageView.mas_right).offset(YNUM(-32));
        make.bottom.equalTo(self.p_byImageView).offset(YNUM(-10));
        make.height.mas_equalTo(YNUM(20));
    }];
    
}

- (void)setInfoModel:(UserInfo *)infoModel {
    _infoModel = infoModel;
    if([kStringUtils(_infoModel.vipType) isEqualToString:@"3"]) {//年
        self.p_byImageView.image = YImage(@"icon_year_vvp.png");
        self.p_kaitongLabel.textColor = COLOR(@"#F5CDAA");
        self.p_chakanLabel.textColor = COLOR(@"#F5CDAA");
    }else if([kStringUtils(_infoModel.vipType) isEqualToString:@"1"]) {//月
        self.p_byImageView.image = YImage(@"icon_month_vvp.png");
        self.p_kaitongLabel.textColor = COLOR(@"#C26600");
        self.p_chakanLabel.textColor = COLOR(@"#C26600");
    }else {
        self.p_byImageView.image = YImage(@"icon_putong_vvp.png");
        self.p_kaitongLabel.textColor = COLOR(@"#FFFFFF");
        self.p_chakanLabel.textColor = COLOR(@"#FFFFFF");
    }
    
    self.p_kaitongLabel.text = [kStringUtils(_infoModel.vipFlag) isEqualToString:@"1"] ? [NSString stringWithFormat:@"已%@",[AYMMKV getStringForKey:KT]] : [NSString stringWithFormat:@"未%@",[AYMMKV getStringForKey:KT]];
    
    if ([kStringUtils(_infoModel.vipFlag) isEqualToString:@"1"]) {
        if (!kStringIsEmpty(_infoModel.vipEndTime)) {
            NSString *time = [_infoModel.vipEndTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
            self.p_timeLabel.text = [NSString stringWithFormat:@"到期时间：%@", time];
        }
    }else {
        self.p_timeLabel.text = @"全场图书免费阅读，首冲有优惠";
    }
    self.p_chakanLabel.text = [kStringUtils(_infoModel.vipFlag) isEqualToString:@"1"] ? @"查看会员权益" : [NSString stringWithFormat:@"立即%@",[AYMMKV getStringForKey:KT]];
}

- (void)setFrame:(CGRect)frame {
    frame.origin.x += YNUM(15);
    frame.size.width -= 2 * YNUM(15);
    [super setFrame:frame];
}


@end
